package org.budo.sharding.proxy.schema;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.core.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.core.metadata.datasource.DataSourceMetas;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.config.yaml.YamlDataSourceParameter;

import lombok.Getter;

/**
 * @author lmw
 */
@Getter
public class BudoShardingLogicSchema extends LogicSchema {
    private ShardingSphereMetaData metaData;

    private ShardingRule shardingRule;

    public BudoShardingLogicSchema(String name, Map<String, YamlDataSourceParameter> dataSources) {
        super(name, dataSources);

        DataSourceMetas dataSourceMetas = null;
        TableMetas tableMetas = new TableMetas(Collections.EMPTY_MAP);
        this.metaData = new ShardingSphereMetaData(dataSourceMetas, tableMetas);

        ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        Collection<String> dataSourceNames = Collections.singleton(name);
        this.shardingRule = new ShardingRule(shardingRuleConfig, dataSourceNames);
    }
}